package com.sliface.web.core;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.appengine.api.datastore.Entity;
import com.sliface.web.app.Facade;
import com.sliface.web.core.MethodInvoker;

public class MethodInvoker {
	private static MethodInvoker instance=null;
	Facade facade = null;
	private MethodInvoker(){
		facade = Facade.getInstance();
	}
    public static MethodInvoker getInstance(){
    	if(instance==null){
    		instance = new MethodInvoker();
    	}
    	return instance;
    }
	
    public void process(HttpServletRequest req,HttpServletResponse resp){
    	String method = req.getServletPath();
    	String targetPage = req.getParameter("targetPage");
    	JsonParser json = new JsonParser( req.getParameter("json") );
    	if(method.equals("/register.do")){ 
    		CommonFunction.toJson(resp, facade.register(json.nextValue(),json.nextValue()), targetPage);
    	}else if(method.equals("/checkAcountExist.do")){
    		CommonFunction.toJson(resp, facade.checkAcountExist(json.nextValue()), targetPage);
    	}else if(method.equals("/logon.do")){
    		CommonFunction.toJson(resp, facade.logon(json.nextValue(),json.nextValue()), targetPage);
    	}
    }
    
    
}
